<?php
namespace modules\game\services\method;

class DoubleP extends IMethod{
	
	public static $_name = __CLASS__;

	//检测牌
	public function test(Array $testPoker){
		$this->_testNum = count($testPoker);
		$this->_testPoker = $testPoker;
		if($this->_testNum !== 2) return false;
		return floor($this->_testPoker[0]/10) === floor($this->_testPoker[1]/10);
	}
	/**
	 * 出牌策略
	 * @param  array $userPoker 用户当前的牌,已模块
	 * @return array 出的牌 | bool 没有此类型的牌，不出
	 */
	public function out($userPoker){//出牌
		$valid = array_filter($userPoker,function($a){
			return count($a) === 2;
		});
		if($valid){
			if($this->test($poker = current($valid))){
				return $poker;
			}
		}
		return false;
	}
	/**
	 * 压牌策略
	 * @param  array $userPoker     我目前的牌
	 * @param  array $opponentPoker 当前需要被压的牌
	 * @param  bool  $intense  是否尽力压牌  true是  or false 否
	 * @return array  出牌 | bool: false 压不住
	 */
	public function suppress($userPoker,$opponentPoker,$intense){
		$oppoKey = current(array_keys($opponentPoker));
		$valid = array_filter($userPoker,function($a){
			return count($a) === 2;
		});
		if($valid){
			foreach($valid as $k => $val){
				if($k > $oppoKey){
					return $val;
				}
			}
		}
		if($intense){//强制拆牌出牌
			return $this->forceSuppress($userPoker,$opponentPoker);
		}
		return false;
	}

}